<?php
/**
 * 装修公司
 */
namespace App\Http\ControllersAdmin;

use App\Service\RolesService;
use App\Validation\ListValidation;
use App\Validation\RolesValidation;
use App\Validation\DeleteValidation;

class RolesController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new ListValidation, $this->request->getJsonRawBody());

		$data = RolesService::getList($raw);
		$count = RolesService::getList($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [createAction 创建]
	 * @return [type] [description]
	 */
	public function createAction()
	{
		$this->getUser();
		$raw = $this->validation(new RolesValidation, $this->request->getJsonRawBody());
		$data = RolesService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$this->getUser();
        $raw = $this->validation(new RolesValidation, $this->request->getJsonRawBody());
		//$id = $this->dispatcher->getParam('id');
		$data = RolesService::getInfo($raw->id);
		return $this->echoJson($data);
	}

	/**
	 * [updateAction 更新]
	 * @return [type] [description]
	 */
	public function updateAction()
	{
		$this->getUser();
		$raw = $this->validation(new RolesValidation, $this->request->getJsonRawBody());

		$data = RolesService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = RolesService::forever($raw->id);
		return $this->echoJson('ok');
	}
}